package com.tbit.uqbike.webmanager.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.object.pojo.dto.AddQuickAccessDTO;
import com.tbit.uqbike.object.pojo.dto.MachineDataDTO;
import com.tbit.uqbike.object.pojo.dto.QuickAccessDTO;
import com.tbit.uqbike.object.pojo.dto.TodoItemsDTO;
import com.tbit.uqbike.object.pojo.vo.MachineDataVO;
import com.tbit.uqbike.object.pojo.vo.QueryQuickAccessVO;
import com.tbit.uqbike.object.pojo.vo.WorkBenchRevenueVO;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.WorkbenchService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.tbit.uqbike.webmanager.controller.BaseController.getLogin;

/**
 * 工作台
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/workbench")
public class WorkbenchController {

    @Resource
    private WorkbenchService workbenchService;


    /**
     * 查询快捷入口列表
     * @param dto dto
     * @return result
     */
    @PostMapping("/queryQuickAccess")
    public Result<QueryQuickAccessVO> queryQuickAccess(@RequestBody @Valid QuickAccessDTO dto){
        return workbenchService.queryQuickAccess(dto);
    }


    /**
     * 编辑快捷入口
     * @return result
     */
    @PostMapping("/addQuickAccess")
    public Result<Object> addQuickAccess(@RequestBody @Valid AddQuickAccessDTO dto){
        return workbenchService.addQuickAccess(dto);
    }


    /**
     * 代办事项
     * @param dto dto
     * @return result
     */
    @PostMapping("/todoItems")
    public Result<Map<String, Object>> todoItems(@RequestBody @Valid TodoItemsDTO dto){
    	return workbenchService.todoItems(dto);
    }


    /**
     * 车辆数据概况
     * @param dto dto
     * @return result
     */
    @PostMapping("/machineData")
    public Result<MachineDataVO> machineData(@RequestBody MachineDataDTO dto){
        return workbenchService.machineData(dto);
    }


    /**
     * 运营数据概况
     * @return result
     */
    @PostMapping("/operatingRevenue")
    public Result<WorkBenchRevenueVO> operatingRevenue(@RequestBody TodoItemsDTO dto){
        if(CollectionUtil.isEmpty(dto.getAccountIds()) || Objects.isNull(dto.getBrandId())){
            return Result.error("参数异常");
        }
        return workbenchService.operatingRevenue(dto.getBrandId(), dto.getAccountIds());
    }


    /**
     * 车辆数据概况
     * @return
     */
    @PostMapping("/machineOverview")
    public Result<Object> machineOverview(@RequestBody TodoItemsDTO dto, HttpServletRequest request){
        if(CollectionUtil.isEmpty(dto.getAccountIds()) || Objects.isNull(dto.getBrandId())){
            return Result.error("参数异常");
        }
        LoginInfo li = getLogin(request);
    	return workbenchService.machineOverview(dto.getAccountIds(), dto.getBrandId(), li);
    }

    /**
     * 用户数据概况
     * @return Result
     */
    @PostMapping("/userOverview")
    public Result<Object> userOverview(@RequestBody TodoItemsDTO dto){
        if(CollectionUtil.isEmpty(dto.getAccountIds()) || Objects.isNull(dto.getBrandId())){
            return Result.error("参数异常");
        }
    	return workbenchService.userOverview(dto.getAccountIds(), dto.getBrandId());
    }




}
